# url = 'https://www.acwing.com/problem/content/3552/'

n = int(input())

s1,s2,s3,s4 = [0,0,0,0]
data = map(int,input().split())
for d in data:
    if d == 1:
        s1 += 1
        s3 = max(s2+1,s3+1)
    else:
        s2 = max(s1+1,s2+1)
        s4 = max(s3+1,s4+1)

print(max(s3,s4))